﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CarHelpDesk.Web.Models.Repositories.TestRepositories
{
    public class QuestionsRepository : IQuestionsRepository
    {
        private List<Question> data;

        public QuestionsRepository()
        {
            data = new List<Question>();
        }

        public QuestionsRepository(List<Question> initialListQuestions)
        {
            data = initialListQuestions;
        }

        #region IQuestionsRepository Members

        public IQueryable<Question> GetQuestions()
        {
            return data.AsQueryable<Question>();
        }

        public IQueryable<Question> SearchByText(string text)
        {
            return from p in data.AsQueryable<Question>()
                   where p.Title.Contains(text) || p.Content.Contains(text)
                   orderby p.CreateDate descending
                   select p;
        }

        public void Create(Question question)
        {
            data.Add(question);
        }

        public Question GetByID(int questionID)
        {
            var v = from p in data.AsQueryable<Question>()
                    where p.ID == questionID
                    select p;
            if (v.Count() == 1) return v.First();
            return null;
        }

        public bool QuestionToogleFavourite(FavouriteQuestion favQuestion)
        {
            throw new NotImplementedException();
        }

        public bool IsFavouritedBy(int questionID, Guid guid)
        {
            throw new NotImplementedException();
        }

        public IQueryable<Question> GetQuestionsFavouritedBy(Guid userID)
        {
            throw new NotImplementedException();
        }

        public void CreateQuestionVote(QuestionVote vote)
        {
            throw new NotImplementedException();
        }

        public QuestionVote GetQuestionVote(Question question, Guid userID)
        {
            throw new NotImplementedException();
        }
        public IQueryable<Question> SearchInAswers(string text)
        {
            throw new NotImplementedException();

        }

        public IQueryable<Question> SearchByTag(List<Tag> categories)
        {
            throw new NotImplementedException();
        }

        public void UpdateQuestionContentById(int id, string content)
        {
            throw new NotImplementedException();
        }

        public void DeleteQuestionById(int id)
        {
            return;
        }

        public void RevertQuestionById(int id)
        {
            return;
        }

        public void ModeratorDeleteQuestionById(int id)
        {
            Question question = (from p in data
                                 where p.ID == id
                                 select p).SingleOrDefault();
            data.Remove(question);
        } 

        public bool QuestionToggleFlagged(QuestionAttentionFlag flaggedQuestion)
        {
            throw new NotImplementedException();
        }

        public IQueryable<Question> GetQuestionsMarkedAsFlagged()
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
